﻿using LuShanTea.Admin.Web.App_Start;
using LuShanTea.DTO;
using LuShanTea.IService;
using LuShanTea.Service;
using LuShanTea.Web.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace LuShanTea.Admin.Web.Controllers
{
    public class LogController : Controller
    {
        public ILogService logSer { get; set; }
        // GET: Log
        [CheckPermission("Log.List")]
        public ActionResult List()
        {
            LogDTO[] model = logSer.GetAll();
            ViewBag.totalCount = model.Count();
            return View(model);
        }
        [HttpGet]
        [CheckPermission("Log.Edit")]
        public ActionResult Edit(long logId)
        {
            var model = logSer.GetById(logId);
            return View(model);
        }
        [CheckPermission("Log.Edit")]
        [HttpPost]
        public ActionResult Edit(long logId,long adminUserId,string describle)
        {
            LogDTO dto = new LogDTO();
            dto.AdminUserId = adminUserId;
            dto.CreateDateTime = DateTime.Now;
            dto.Describle = describle;
            dto.Id = logId;
            logSer.Updata(dto);
            return Json(new AjaxResult { Status = "ok" });
        }
        [CheckPermission("Log.Delete")]
        public ActionResult Delete(long logId)
        {
            logSer.MakeDelete(logId);
            return Json(new AjaxResult { Status = "ok" });
        }
        [CheckPermission("Log.Delete")]
        public ActionResult BatchDel(long[] logIds)
        {
            foreach (var logId in logIds)
            {
                logSer.MakeDelete(logId);
            }
            return Json(new AjaxResult { Status = "ok" });
        }
    }
}